package com.mezz.bones.im.logic.listener;

import com.mezz.bones.im.common.event.MessageReceivedEvent;
import com.mezz.bones.im.common.message.base.MessageHeader;
import com.mezz.bones.im.logic.service.IMessageReceiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;

/**
 * @Author: zhuang
 * @Date: 2024/12/2 13:56
 * @Description: TODO
 * @Version: 1.0
 **/

@Component
@Slf4j
public class LogicMessageListener {
    @Resource
    private IMessageReceiveService messageReceiveService;

    @EventListener
    public void handleMessageReceive(MessageReceivedEvent event) {

        //从网关层过来的消息都默认开启ACK回复 如果是直接业务层发起的则根据需求调整
        MessageHeader header = event.getImMessage().getHeader();
        header.setAck(true);
        try {
            messageReceiveService.handleMessage(event);
        } catch (Exception e) {
            log.error("handleMessageReceive error",e);
        }
    }
}
